package com.sky.renren.activity;

import com.sky.renren.R;
import com.sky.renren.control.LoginController;
import com.sky.renren.library.RenrenWebViewClient;
import com.sky.renren.library.WebInterface;

import android.os.Bundle;
import android.os.Handler;
import android.os.Handler.Callback;
import android.os.HandlerThread;
import android.os.Message;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.WebView;
//import android.view.WindowManager;
import android.widget.Toast;

public class SplashActivity extends BaseActivity implements Callback, WebInterface{
	
	private Handler handler = null;
	private HandlerThread handlerThread = null;
	
	private WebView web = null;
	private LoginController loginController = null;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//		getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.splash);
        handlerThread = new HandlerThread("splash");
        handlerThread.start();
        handler = new Handler(handlerThread.getLooper(), this);
        loginController = new LoginController(this);
        loginController.loadWeb();
    }
    
    public void  loadWeb(String url) {
    	Log.d("splashactivity", url);
    	setupWebView();
    	web.loadUrl(url);
//    	web.loadUrl(getResources().getString(R.string.url));
    }
    
	private void setupWebView() {
        web = (WebView)findViewById(R.id.login_web);
//      LayoutInflater inflater = getLayoutInflater();
//      web =  (WebView)inflater.inflate(R.layout.loginweb, null);
		web.setVerticalScrollBarEnabled(false);
		web.setHorizontalScrollBarEnabled(false);
		web.getSettings().setJavaScriptEnabled(true);
		web.setWebViewClient(new RenrenWebViewClient(this));
		web.loadUrl(getResources().getString(R.string.url));
	}
    

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			Message msg = handler.obtainMessage();
			handler.sendMessage(msg);
		}
		return super.onTouchEvent(event);
	}



	@Override
	public boolean handleMessage(Message msg) {
//		startActivity(new Intent(SplashActivity.this, LoginActivity.class));
//		startActivity(new Intent(SplashActivity.this, LoginWebActivity.class));
//		finish();
		return true;
	}

	@Override
	public void onPageFinished() {
//		Intent intent = new Intent(SplashActivity.this, LoginWebActivity.class);
//		Intent intent = new Intent(SplashActivity.this, ContactActivity.class);
//		Bundle bundle = new Bundle();
//		bundle.put
//		intent.putExtras(bundle);
//		startActivity(intent);
//		finish();
		web.setVisibility(View.VISIBLE);
	}
}